/**
* This file contains function definitions for an Integer Queue Implementation 
*/

#include<stdlib.h>
#include<string.h>

#include "queue.h"
#include "zmalloc.h"

Queue *initQueue() {

	Queue *Q;
	Q = listCreate();
        return(Q);
}

void enqueue(Queue *Q,void *e)
{
	listAddNodeTail(Q,e);
	return;
}

void *dequeue(Queue *Q)
{
	void *xvalue;
	listNode *xnode;
	xvalue = NULL;
	
	do {

	if ( listLength(Q) == 0 ) break;

	 	xnode = Q->head;
		if ( xnode == NULL ) break;

	 	xvalue = xnode->value;
	 	Q->head = Q->head->next;

		if ( Q->head != NULL ) 
	 	   Q->head->prev = NULL;

		Q->len--;
		zfree(xnode);
	    
	} while(0);

     return(xvalue);
}

int isQueueEmpty(Queue *Q)
{
    int retval = 0;

    do {

	if ( Q == NULL) break;

	if(Q->head==Q->tail) {
		retval = 1;
	} else {
		retval = 0;
	}

    } while(0);

    return(retval);
}

int isQueueFull(Queue *Q)
{
	return 0;
}


void freeQueue(Queue *Q)
{
	listRelease(Q);
	return;
}
